import Vue from 'vue'
import Router from 'vue-router'
import Home from '../views/Home'
import Cart from '../views/Cart'
import My from  '../views/My'
import Classify from '../views/Classify'
import Living from '../views/Living'
import Login from '../views/Login'

Vue.use(Router)

const router=new Router({
  routes: [
    {
      path:"*",
      redirect:'/'
    },
    {
      path: '/',
      name: 'Login ',
      component: Login
    },
    {
      path: '/home',
      name: 'Home',
      component: Home,

    },
    {
      path: '/cart',
      name: 'Cart',
      component: Cart
    },
    {
      path: '/my',
      name: 'My',
      component: My
    },
    {
      path: '/classify',
      name: 'Classify',
      component: Classify
    },
    {
      path: '/living',
      name: 'Living',
      component: Living
    }
  ]
})

router.beforeEach((to,from,next)=>{
  if (to.path==='/') {
    next()
    return
  }
  if(to.path!=='/'){
    if (sessionStorage.getItem('token')){
      next()
    }else {
      router.push('/')
    }
}

})
export default router
